package com.my.note.mapper;

import com.my.note.pojo.RoleData;
import com.my.note.pojo.RoleResourceData;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

/**
 * @author lilun <a href="mailto:lil@chsi.com.cn">lilun</a>
 * @version $Id$ 2019年03月21 9:31
 */
@Mapper
@Component
public interface RoleMapper {

    @Select("select * from note_role where id = #{id}")
    RoleData getRoleById(@Param("id") String id);

    @Select("select * from note_role where roleName = #{roleName}")
    RoleData getRoleByRoleName(@Param("roleName") String roleName);

    @Select("select * from note_role_resource where resourceId = #{resourceId}")
    List<RoleResourceData> getRoleResourceListByResId(@Param("resourceId") String resourceId);

    @Select("select * from note_role_resource where roleId = #{roleId}")
    List<RoleResourceData> getRoleResourceListByRoleId(@Param("roleId") String roleId);

    @Select("select * from note_role")
    List<RoleData> getRoleList();

    @Delete("delete from note_role where id=#{id}")
    void deleteRole(@Param("id") String id);

    @Delete("delete from note_role_resource where id=#{id}")
    void deleteRoleResource(@Param("id") String id);

    @Insert("insert into note_role(id,roleName,mark) values(#{id},#{roleName},#{mark})")
    void saveRole(@Param("id") String id, @Param("roleName") String roleName, @Param("mark") String mark);

    @Insert("insert into note_role_resource(id,roleId,resourceId) values(#{id},#{roleId},#{resourceId})")
    void saveRoleResource(@Param("id") String id, @Param("roleId") String roleId, @Param("resourceId") String resourceId);

}
